Security News
RubyGems.org Adds New Maintainer Role
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
babel-plugin-transform-es2015-classes
Advanced tools
The babel-plugin-transform-es2015-classes package is a Babel plugin that transforms ES2015 (ES6) class syntax into a form that can be understood by older JavaScript environments that do not support ES2015 classes. This allows developers to write modern JavaScript code while maintaining compatibility with older environments.
Class Declaration Transformation
Transforms ES2015 class declarations into a form that can be understood by older JavaScript environments.
class Example { constructor() { this.value = 42; } getValue() { return this.value; } }
Inheritance Transformation
Transforms ES2015 class inheritance syntax into a form that can be understood by older JavaScript environments.
class Parent { constructor() { this.parentValue = 'parent'; } } class Child extends Parent { constructor() { super(); this.childValue = 'child'; } }
Static Methods Transformation
Transforms ES2015 static methods into a form that can be understood by older JavaScript environments.
class Example { static staticMethod() { return 'static method'; } }
This package transforms ES2015 arrow functions into ES5 function expressions. While it focuses on arrow functions rather than classes, it serves a similar purpose of enabling modern JavaScript syntax in older environments.
This package transforms ES2015 parameter syntax (such as default parameters and rest parameters) into ES5-compatible code. It complements babel-plugin-transform-es2015-classes by handling another aspect of ES2015 syntax.
Compile ES2015 classes to ES5
Built-in classes such as Date
, Array
, DOM
etc cannot be properly subclassed
due to limitations in ES5 (for the es2015-classes plugin).
You can try to use babel-plugin-transform-builtin-extend based on Object.setPrototypeOf
and Reflect.construct
, but it also has some limitations.
npm install --save-dev babel-plugin-transform-es2015-classes
.babelrc
(Recommended).babelrc
// without options
{
"plugins": ["transform-es2015-classes"]
}
// with options
{
"plugins": [
["transform-es2015-classes", {
"loose": true
}]
]
}
babel --plugins transform-es2015-classes script.js
require("babel-core").transform("code", {
plugins: ["transform-es2015-classes"]
});
loose
boolean
, defaults to false
.
Please note that in loose mode class methods are enumerable. This is not in line with the spec and you may run into issues.
Under loose mode, methods are defined on the class prototype with simple assignments instead of being defined. This can result in the following not working:
class Foo {
set bar() {
throw new Error("foo!");
}
}
class Bar extends Foo {
bar() {
// will throw an error when this method is defined
}
}
When Bar.prototype.foo
is defined it triggers the setter on Foo
. This is a
case that is very unlikely to appear in production code however it's something
to keep in mind.
FAQs
Compile ES2015 classes to ES5
The npm package babel-plugin-transform-es2015-classes receives a total of 942,504 weekly downloads. As such, babel-plugin-transform-es2015-classes popularity was classified as popular.
We found that babel-plugin-transform-es2015-classes demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 6 open source maintainers collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
RubyGems.org has added a new "maintainer" role that allows for publishing new versions of gems. This new permission type is aimed at improving security for gem owners and the service overall.
Security News
Node.js will be enforcing stricter semver-major PR policies a month before major releases to enhance stability and ensure reliable release candidates.
Security News
Research
Socket's threat research team has detected five malicious npm packages targeting Roblox developers, deploying malware to steal credentials and personal data.